package 代码记录.指定公司代码练习记录.华为_2024.分值100;

import java.util.*;

/**
 * @author zx
 * @create 2024-01-31 19:02
 */
public class 数组排序_16 {
    /**
     * 按照前K个高频元素的做法做的(但是不确定能否过了所有的测试用例)
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] temp = str.split(",");
        int[] arr = new int[temp.length];
        for(int i = 0;i < arr.length;i++){
            arr[i] = Integer.parseInt(temp[i]);
        }
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i < arr.length;i++){
            map.put(arr[i],map.getOrDefault(arr[i],0) + 1);
        }
        List<Map.Entry<Integer,Integer>> entries = new ArrayList<>(map.entrySet());
        Collections.sort(entries, new Comparator<Map.Entry<Integer, Integer>>() {
            @Override
            public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                return o2.getValue() - o1.getValue();
            }
        });
        map.forEach((key,value) -> {
            System.out.println(key + " - " + value);
        });
        int[] res = new int[map.size()];
        for(int i = 0;i < map.size();i++){
            res[i] = entries.get(i).getKey();
        }
        System.out.println(Arrays.toString(res));
    }
}
